package com.team.employment.web.admin.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.team.employment.model.entity.CompanyInfo;
import com.team.employment.model.entity.JobApplication;
import com.team.employment.model.entity.RecruitmentInfo;
import com.team.employment.model.entity.ResumeInfo;
import com.team.employment.web.admin.dto.ResumeSearchDto;
import com.team.employment.web.admin.mapper.CompanyInfoMapper;
import com.team.employment.web.admin.mapper.RecruitmentInfoMapper;
import com.team.employment.web.admin.service.ResumeInfoService;

import com.team.employment.web.admin.mapper.ResumeInfoMapper;
import com.team.employment.web.admin.vo.SubmitResumeInfoVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
* @author jade
* @description 针对表【resume_info(简历信息表)】的数据库操作Service实现
* @createDate 2025-04-11 15:49:27
*/
@Service
public class ResumeInfoServiceImpl extends ServiceImpl<ResumeInfoMapper, ResumeInfo>
    implements ResumeInfoService{
    @Autowired
    private ResumeInfoMapper resumeInfoMapper;
    @Autowired
    private RecruitmentInfoMapper recruitmentInfoMapper;

    @Autowired
    private CompanyInfoMapper companyInfoMapper;

    @Override
    public IPage<ResumeInfo> pageQueryInfo(IPage<ResumeInfo> page, ResumeSearchDto resumeSearchDto){
        IPage<ResumeInfo> list = resumeInfoMapper.pageQueryInfo(page,resumeSearchDto);
        return list;
    }

    @Override
    public IPage<SubmitResumeInfoVo> getJobApplication(Long id, List<JobApplication> jobApplications, IPage<SubmitResumeInfoVo> page) {

        LambdaQueryWrapper<RecruitmentInfo> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        LambdaQueryWrapper<ResumeInfo> lambdaQueryWrapper1 = new LambdaQueryWrapper<>();
        LambdaQueryWrapper<CompanyInfo> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(CompanyInfo::getId,id);
        CompanyInfo companyInfo = companyInfoMapper.selectOne(queryWrapper);



        List<SubmitResumeInfoVo> list = new ArrayList<>();
        jobApplications.forEach(jobApplication -> {
            SubmitResumeInfoVo vo = new SubmitResumeInfoVo();

            RecruitmentInfo recruitmentInfo = recruitmentInfoMapper.selectById(jobApplication.getRecruitmentId());

            ResumeInfo resumeInfo = resumeInfoMapper.selectById(jobApplication.getResumeId());

            BeanUtils.copyProperties(resumeInfo,vo);
            vo.setCompanyName(companyInfo.getName());
            vo.setRecruitmentId(recruitmentInfo.getId());
            vo.setRecruitmentPosition(recruitmentInfo.getPosition());

            list.add(vo);
        });
        IPage<SubmitResumeInfoVo> vo = page.setRecords(list);
        return vo;
    }

}




